﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SistemaInformativoTuristico
{
    public partial class Formulario_web13 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnNuevo_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                string fileExt =
                   System.IO.Path.GetExtension(FileUpload1.FileName);

                if (fileExt == ".jpg")
                {
                    try
                    {
                        FileUpload1.SaveAs("C:\\Uploads\\" + FileUpload1.FileName);
                        lblFoto.Text = "File name: " +
                            FileUpload1.PostedFile.FileName + "<br>" +
                            FileUpload1.PostedFile.ContentLength + " kb<br>" + "Content type: " +
                            FileUpload1.PostedFile.ContentType;
                    }
                    catch (Exception ex)
                    {
                        lblFoto.Text = "ERROR: " + ex.Message.ToString();
                    }
                }
                else
                {
                    lblFoto.Text = "Only .jpg files allowed!";
                }
            }
            else
            {
                lblFoto.Text = "You have not specified a file.";
            }
        

            ClaseOcioyDiversion clase = new ClaseOcioyDiversion();
            bool r;

            Int32 idOcio= Convert.ToInt32(lbl_ID.Text);
            Int32 idCanton = Convert.ToInt32(ListCanton.Text);
            

            r= clase.guardarDatosOcioyDiversion(idOcio, ListTipo.Text,txtNombre.Text,idCanton,txtDireccion.Text,txtDescripcion.Text,txtTelefonos.Text,lblFoto.Text);


            if (r == true){
                 Response.Write("<script languaje = javascript>alert('Inserto bien');</script>");

            }
            else
            {
Response.Write("<script languaje= javascript>alert('Inserto mal');</script>");

            }
        }
        }
    }
